<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 
        ref加在元素上面，可以用于获取dom节点
        ref加在组件上面，可以用来获取子组件的实例
       -->
      <h2>组件添加ref</h2>
      <child ref="child"></child>
    </div>

    <script src="./lib/Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      const Child = {
        data() {
          return {
            count: 20,
          };
        },
        methods: {
          fn() {
            console.log("child fn");
          },
        },
        template: `
          <div>child子组件</div>
        `,
      };

      createApp({
        data() {
          return {};
        },
        components: {
          Child,
        },
        mounted() {
          console.log(this.$refs.child.count);
          this.$refs.child.fn();
        },
      }).mount("#app");
    </script>
  </body>
</html>
